clear all

use "study5data.dta"

*post-only
reg postdv i.treat##i.RD predv_W1 ideo if expcond==0
est store post

*quasi
reg postdv i.treat##i.RD predv_W1 quasidv ideo if expcond==1
est store quasi

*prepost
reg postdv i.treat##i.RD predv_W1 predv_W2 ideo if expcond==2
est store pre

*differences in coefficients
suest post quasi pre
test[post_mean]1.treat#1.RD=[quasi_mean]1.treat#1.RD
test[post_mean]1.treat#1.RD=[pre_mean]1.treat#1.RD


*moderator graph
gen x=_n
replace x=. if _n>3
gen est=.
gen se=.

reg postdv i.treat##i.RD predv_W1 ideo if expcond==0
est store postc
replace se=_se[1.treat#1.RD] in 1
replace est=_b[1.treat#1.RD] in 1
reg postdv i.treat##i.RD predv_W1 quasidv ideo if expcond==1
est store quasic
replace se=_se[1.treat#1.RD] in 3
replace est=_b[1.treat#1.RD] in 3
reg postdv i.treat##i.RD predv_W1 predv_W2 ideo if expcond==2
est store prec
replace se=_se[1.treat#1.RD] in 2
replace est=_b[1.treat#1.RD] in 2

gen lo=est-1.96*se
gen hi=est+1.96*se


twoway (scatter est x if x==1, mcol(black)) (scatter est x if x==2, mcol(gray)) (scatter est x if x==3, mcol(sky)) ///
	(rcap lo hi x if x==1, lcol(black)) (rcap lo hi x if x==2, lcol(gray)) (rcap lo hi x if x==3, lcol(sky) ///
	xsc(range(.5 3.5)) xlab(1 "Post-only" 2 "Pre-post" 3 "Quasi", labsize(medsmall)) yline(0) legend(off) ///
	xtitle("") ylab(-.5(.5)2, labsize(medsmall)) plotregion(margin(zero)) graphregion(margin(1 1 1 1)) ///
	subtitle("Study 5: Prescriptions") saving(study5.gph, replace))

	
	
* "main effect" graph for appendix
reg postdv i.treat i.RD predv_W1 if expcond==0
est store m1
reg postdv i.treat i.RD predv_W1 quasi* if expcond==1
est store m2
reg postdv i.treat i.RD predv_W1 predv_W2 if expcond==2
est store m3
reg postdv i.treat##i.expcond i.RD predv_W1

suest m1 m2 m3
test [m1_mean]1.treat=[m2_mean]1.treat
test [m1_mean]1.treat=[m3_mean]1.treat

coefplot m1 m2 m3, keep(1.treat) vert yline(0) xlab(.75 "Post-only" 1 "Pre-post" 1.25 "Quasi") ylab(-.9(.3).6) legend(off) subtitle("Study 5. Main Treatment Effects")


* marginal effect graph for appendix
reg postdv i.treat##i.RD##i.expcond predv_W1
lincomest 1.treat
est store r1
reg postdv i.treat##i.RD##i.expcond predv_W1
lincomest 1.treat + 1.treat#1.expcond
est store r2
reg postdv i.treat##i.RD##i.expcond predv_W1
lincomest 1.treat + 1.treat#2.expcond
est store r3
reg postdv i.treat##i.RD##i.expcond predv_W1
test 1.treat=1.treat + 1.treat#1.expcond
test 1.treat=1.treat + 1.treat#2.expcond

reg postdv i.treat##i.RD##i.expcond predv_W1
lincomest 1.treat + 1.treat#1.RD
est store d1
reg postdv i.treat##i.RD##i.expcond predv_W1
lincomest 1.treat + 1.treat#1.RD + 1.treat#1.expcond + 1.treat#1.RD#1.expcond
est store d2
reg postdv i.treat##i.RD##i.expcond predv_W1
lincomest 1.treat + 1.treat#1.RD + 1.treat#2.expcond + 1.treat#1.RD#2.expcond
est store d3
reg postdv i.treat##i.RD##i.expcond predv_W1
test 1.treat + 1.treat#1.RD=1.treat + 1.treat#1.RD + 1.treat#1.expcond + 1.treat#1.RD#1.expcond
test 1.treat + 1.treat#1.RD=1.treat + 1.treat#1.RD + 1.treat#2.expcond + 1.treat#1.RD#2.expcond


coefplot r1 r3 r2, vert yline(0) ylab(-1.5(.5)1) legend(off) offset(0) asequation ///
	swapnames coeflabels(r1="Posttest" r2="Quasi" r3="Prepost") subtitle("Republican Respondents") ///
	ytitle("Treatment Effect") saving(marg_r.gph, replace)
coefplot d1 d3 d2, vert yline(0) ylab(-1.5(.5)1) legend(off) offset(0) asequation ///
	swapnames coeflabels(d1="Posttest" d2="Quasi" d3="Prepost") subtitle("Democratic Respondents") ///
	ytitle("Treatment Effect") saving(marg_d.gph, replace)
graph combine marg_r.gph marg_d.gph, subtitle("Study 5. Treatment Effects by Respondent Partisanship") ///
	note("Plot shows marginal treatment effect estimated separately for Democrats and Republicans.", size(vsmall))
